//
//  UserService.m
//  KutulusLaw
//
//  Created by phuc phuc on 12/11/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "UserService.h"
#import "MyApiClient.h"
#import "Constant.h"
#import "JSONKit.h"
#import "UserDTO.h"
#import "KChangePasswordDAO.h"

@implementation UserService


//this method get session id
+ (void) checkLoginWithUserName :(NSString*)_username pass : (NSString*) _pass :(void (^)(id dictionary, NSError *error))block
{
	NSMutableDictionary *params = [NSMutableDictionary dictionary];
	[params setObject: kAPI_MODULE forKey: kKEY_MODULE];
	[params setObject: @"mobile_authenticate" forKey: kKEY_ACTION];
	[params setObject: @"1" forKey: kKEY_AJAX_ACTION];
	[params setObject: _username forKey: @"username"];
	[params setObject: _pass forKey: @"password"];
	
	[[MyApiClient sharedClient]  postPath:@"" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
		responseObject = [responseObject objectFromJSONData];
		NSLog(@"status  : %@",[responseObject objectForKey:@"status"]);
		
        block(responseObject,nil);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"error  : %@",[error description]);
		block ([[operation responseData] objectFromJSONData],error);
    }];
}

+ (void) getProfileWithSessionID :(NSString*) _sessionID :(void (^)(id dictionary, NSError *error))block
{
	NSMutableDictionary *params = [NSMutableDictionary dictionary];
	[params setObject: @"profilemodule" forKey: @"module"];
	[params setObject: @"mobile_getmyprofile" forKey: @"action"];
	[params setObject: @"1" forKey: @"ajax_action"];
	[params setObject: _sessionID forKey: @"session_id"];
	
	
	[[MyApiClient sharedClient]  postPath:@"" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
		responseObject = [responseObject objectFromJSONData];
		NSLog(@"status  : %@",[responseObject objectForKey:@"status"]);
		
        block(responseObject,nil);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"error  : %@",[error description]);
		block ([[operation responseData] objectFromJSONData],error);
    }];
}


@end
